#include "ADUContactFilter.h"
#include "ADUDuck.h"
#include "ADUConstant.h"
#include "ADUGameManager.h"


bool MyContactFilter::ShouldCollide(b2ParticleSystem * particleSystem,int32 particleIndexA,int32 particleIndexB) {

	return false;
}


bool MyContactFilter::ShouldCollide(b2Fixture* fixture,
							   b2ParticleSystem* particleSystem,
							   int32 particleIndex) {
    
    GameManager::getInstance()->SetColisionCache(particleIndex, true);
	
	return true;
}

bool MyContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) {
    
	b2Body* bodyA = fixtureA->GetBody();
	b2Body* bodyB = fixtureB->GetBody();
	Sprite* user_dataA = (Sprite*)bodyA->GetUserData();
	Sprite* user_dataB = (Sprite*)bodyB->GetUserData();
	if(user_dataA == NULL || user_dataB == NULL) return true;
    
    
    if((user_dataA->getTag() == TAG_PIPEHEAD && user_dataB->getTag() == TAG_DUCK)) {
		return false;
	}
    
    if((user_dataA->getTag() == TAG_PIPEHEAD && user_dataB->getTag() == TAG_DUCK)) {
		return false;
	}
    

	if((user_dataA->getTag() == TAG_BASIN && user_dataB->getTag() == TAG_DUCK)) {
		Basin* basin = (Basin*)user_dataA;
        Duck* duck = (Duck*)user_dataB;
        duck->SetLastBindBasin(basin);
	} 
	if((user_dataA->getTag() == TAG_DUCK && user_dataB->getTag() == TAG_BASIN)) {
		Basin* basin = (Basin*)user_dataB;
        Duck* duck = (Duck*)user_dataA;
        
        duck->SetLastBindBasin(basin);
	}

	return true;
}


